﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;

namespace MyMovieInfo
{
    class Program
    {
        static void Main(string[] args)
        {
            //command line arguments
            string theMovieFilePath = ArgumentUtils.GetArgument(args, ArgumentUtils.Args.MovieFilePath);
            string theOutputPath = ArgumentUtils.GetArgument(args, ArgumentUtils.Args.OutputPath);

            //read file names from file system
            List<string> fileList = FileUtils.GetListFromFileSystem(theMovieFilePath, ".avi");

            if (fileList.Count > 0)
            {                
                //DIP - send in the clowns
                MovieResolver resolver = new MovieResolver(
                    new MovieListFromFileNames(fileList), 
                    new XMLPersistenceService(Path.Combine(theOutputPath, "movies-DIP.xml")));
                resolver.RegisterLookupService(new NetflixLookup());
                resolver.RegisterLookupService(new IMDBLookup());
                resolver.RegisterLookupService(new TMDBLookup());

                resolver.ExecuteQueries();
                resolver.SaveResults();

                #region Display to the console
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Found Movies");
                resolver.Movies.Where(p => p.MatchFound == true).ToList().ForEach(e => PrintMovieToConsole(e));

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Movies Not Found");
                resolver.Movies.Where(p => p.MatchFound == false).ToList().ForEach(e => PrintMovieToConsole(e));
                #endregion
            }
            else
            {
                Console.WriteLine(String.Format("No files found in \"{0}\".", theMovieFilePath));
            }
            Console.ReadKey();
        }

        #region Pretty Console Printer
        private static void PrintMovieToConsole(Movie movie)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("{0} - {1}", movie.Name, movie.Year);
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("{0}\n{1}\n{2}\nSource:{3}\n\n", movie.Synopsis, movie.CoverURL, movie.FilePath, movie.Source);
        }
        #endregion
    }

}
